package hrms.controller;

import hrms.entity.Finance;
import hrms.entity.Result;
import hrms.service.FinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/finance")
public class FinanceController {
    @Autowired
    FinanceService financeService;

    @GetMapping("/findByDate")
    public Result findByDate(Integer year, Integer month){
        List<Finance> finances = financeService.findByDate(year, month);
        if(finances.size()==0){
            return Result.fail().error("查询不到该条件的财务情况");
        }
        Map<String,Object> map = new HashMap<>();
        map.put("finances",finances);
        return Result.success().addMap(map);
    }

    @GetMapping("/findAllFinance")
    public Result findAllFinance(){
        List<Finance> finances = financeService.findAllFinances();
        if(finances.size() == 0){
            return Result.fail().error("查询不到任何财务情况");
        }
        Map<String,Object> map = new HashMap<>();
        map.put("finances",finances);
        return Result.success().addMap(map);
    }
}
